from django.contrib import admin
from bike.models import Staff, Violation
from bike.models import Plate
from bike.models import Car
from bike.models import Student
from bike.models import Teacher


@admin.register(Staff)
class StaffAdmin(admin.ModelAdmin):
    list_display = ("dept", "name", "phone", "is_leader")
    list_filter = ("dept", "is_leader")
    search_fields = ("name", "phone")
    autocomplete_fields = []


@admin.register(Plate)
class PlateAdmin(admin.ModelAdmin):
    list_display = (
        "kind",
        "number",
        "status",
    )
    list_filter = (
        "kind",
        "status",
    )
    search_fields = ("number",)
    autocomplete_fields = []


@admin.register(Car)
class CarAdmin(admin.ModelAdmin):
    list_display = (
        "plate",
        "brand",
    )
    search_fields = ("plate__number",)
    autocomplete_fields = ["plate"]


@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):
    list_display = ("car", "college", "major", "grade", "name", "phone")
    list_filter = (
        "college",
        "major",
        "grade",
    )
    search_fields = ("car__plate__number", "name", "phone")
    autocomplete_fields = ["car"]


@admin.register(Teacher)
class TeacherAdmin(admin.ModelAdmin):
    list_display = ("car", "dept", "name", "phone")
    list_filter = ("dept",)
    search_fields = ("car__plate__number", "name", "phone")
    autocomplete_fields = ["car"]


# 车辆违章
@admin.register(Violation)
class ViolationAdmin(admin.ModelAdmin):
    list_display = ("car", "reason", "staff", "created")
    list_filter = ("staff",)
    search_fields = ("car__plate__number", "reason", "staff__name")
    autocomplete_fields = ["car", "staff"]
